package com.chainyoung.trademarket.mvp.presenter;

import com.chainyoung.common.base.CommonSubscriber;
import com.chainyoung.common.bean.UserInfo;
import com.chainyoung.common.di.scope.ActivityScope;
import com.chainyoung.common.mvp.BasePresenter;
import com.chainyoung.common.utils.RxUtils;
import com.chainyoung.trademarket.R;
import com.chainyoung.trademarket.mvp.contract.RegisterContract;


import java.util.TreeMap;

import javax.inject.Inject;

import static com.chainyoung.common.constant.LibConstant.IS_CUSTOME_SIZE;

@ActivityScope
public class RegisterPresenter extends BasePresenter<RegisterContract.Model, RegisterContract.View> {


    @Inject
    public RegisterPresenter(RegisterContract.Model model, RegisterContract.View rootView) {
        super(model, rootView);
    }


    public void sendCode(TreeMap<String, Object> map) {

        addSubscribe(mModel.getSendCode(map)
                .compose(RxUtils.<String>rxSchedulerHelper())
                .subscribeWith(new CommonSubscriber<String>(mView, true, IS_CUSTOME_SIZE) {
                    @Override
                    public void onNext(String object) {
                        mView.showMsg(R.string.validate_code_sent);
                        mView.onSendCodeSuccess(object);
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                    }
                }));
    }

    public void getRegister(TreeMap<String, Object> map) {
        addSubscribe(mModel.getRegiseter(map)
                .compose(RxUtils.<UserInfo>rxSchedulerHelper())
                .subscribeWith(new CommonSubscriber<UserInfo>(mView, true, IS_CUSTOME_SIZE) {
                    @Override
                    public void onNext(UserInfo userInfo) {
                        mView.onRegisterSuccess(userInfo);
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                    }
                }));
    }


}
